﻿using Sunny.Lib;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Sunny.Lib.Test
{
    
    
    /// <summary>
    ///This is a test class for PollWaitUtilityTest and is intended
    ///to contain all PollWaitUtilityTest Unit Tests
    ///</summary>
    [TestClass()]
    public class PollWaitUtilityTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        /// A test for PollWait
        /// Check D:\1.txt exist
        /// Every 5 seconds to check one time, if exist return true, otherwize next 5 seconds check again utill 1 minuter pass, still not exist return false
        ///</summary>
        [TestMethod()]
        public void PollWaitTest()
        {
            PollWaitUtility.PollCondition conditionDelegate = ()=>
            {
                string filePath = @"D:/1.txt";
                bool isExistFile = System.IO.File.Exists(filePath);

                // TODO: Trace log
                string logMessage = string.Format("Not exist file path:{0}", filePath);
                
                return isExistFile;
            };

            TimeSpan retryInterval = TimeSpan.FromSeconds(5); 
            TimeSpan timeout =  TimeSpan.FromMinutes(1); 
            bool expected = true; 
            bool actual;
            actual = PollWaitUtility.PollWait(conditionDelegate, retryInterval, timeout);
            Assert.AreEqual(expected, actual);
        }
    }
}
